package com.qyhl.module_home.home.fragment2;

import androidx.fragment.app.Fragment;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.launcher.ARouter;
import com.qyhl.module_home.home.fragment2.main.HomeListFragment;
import com.qyhl.module_home.home.panzhou.PanZhouListFragment;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.constant.ServicePathConstant;
import com.qyhl.webtv.commonlib.entity.config.AppConfigBean;
import com.qyhl.webtv.commonlib.service.ActivitiesService;
import com.qyhl.webtv.commonlib.service.LiveService;
import com.qyhl.webtv.commonlib.service.NewsService;
import com.qyhl.webtv.commonlib.service.PracticeService;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/3/19.
 */

public class HomePresenterImpl implements HomeContract.HomeViewPresenter {
    private HomeContract.HomeView homeView;

    /**
     * 圈子服务
     */
    @Autowired(name = ServicePathConstant.NEWS_SERVICE)
    public NewsService newsService;

    @Autowired(name = ServicePathConstant.LIVE_SERVICE)
    public LiveService liveService;

    @Autowired(name = ServicePathConstant.ACTIVITY_SERVICE)
    public ActivitiesService activitiesService;

    @Autowired(name = ServicePathConstant.PRACTICE_SERVICE)
    public PracticeService practiceService;


    public HomePresenterImpl(HomeContract.HomeView homeView) {
        this.homeView = homeView;
        ARouter.getInstance().inject(this);
    }

    @Override
    public void onDestroy() {
        homeView = null;
    }


    @Override
    public void setConfig(List<AppConfigBean.ThreeMenus> secMenusList) {
        //是否显示导航
        ArrayList<Fragment> fragmentList = new ArrayList<>();
        String[] names;
        if (secMenusList != null && secMenusList.size() != 0) {
            names = new String[secMenusList.size() + 1];
            names[0] = "推荐";
            if (CommonUtils.getInstance().getSite() == 175 || CommonUtils.getInstance().getSite() == 222) {
                fragmentList.add(new PanZhouListFragment());
            } else {
                fragmentList.add(new HomeListFragment());
            }

            for (int i = 0; i < secMenusList.size(); i++) {
                AppConfigBean.ThreeMenus secMenu = secMenusList.get(i);
                names[i + 1] = secMenu.getMenuName();
                switch (secMenu.getTypeId()) {
                    case 1:
                        if (secMenu.getStyleId() == 1) {
                            //资讯样式
                            fragmentList.add(new TextFragment());
                        } else {
                            //节目样式//---a
                            fragmentList.add(newsService.getProgramFragment(secMenu.getSecondId() + "", "1"));
                        }
                        break;
                    case 2:
                        fragmentList.add(new TextFragment());
                        break;
                    case 3:
                        fragmentList.add(liveService.getLiveListFragment(""));
                        break;
                    case 4:
                        fragmentList.add(newsService.getTitleNewsFragment("", secMenu.getUrl()));
                        break;
                    case 6:
                        //新闻列表
                        if (secMenu.getStyleId() == 5) {
                            fragmentList.add(newsService.getNanBuNewListFragment(secMenu.getUrl(), 6));
                        } else {
                            fragmentList.add(newsService.getNewListFragment(secMenu.getUrl()));
                        }
                        break;
                    case 7:
                        //新趣汇
                        fragmentList.add(newsService.getGoodLifeFragment());
                        break;
                    case 9:
                        switch (secMenu.getStyleId()) {
                            case 1:
                                //乡镇
                                fragmentList.add(newsService.getTownListFragment("", secMenu.getUrl()));
                                break;
                            case 2:
                                //政务
                                fragmentList.add(newsService.getGovernmentListFragment("", secMenu.getUrl()));
                                break;
                            case 3:
                                //专题
                                fragmentList.add(newsService.getSpecialListFragment("", secMenu.getUrl(), false));
                                break;
                            case 4:
                                fragmentList.add(newsService.getTown3ListFragment("", secMenu.getUrl()));
                                break;
                            default:
                                break;
                        }
                        break;
                    case 10:
                        fragmentList.add(liveService.getTeleTextFragment(""));
                        break;
                    case 12:
                        //传统直播混合列表
                        fragmentList.add(liveService.getMixLiveListFragment("", ""));
                        break;
                    case 13:
                        //传统直播音频列表
                        fragmentList.add(liveService.getMixLiveListFragment("", "2"));
                        break;
                    case 14:
                        // 传统直播视频列表
                        fragmentList.add(liveService.getMixLiveListFragment("", "1"));
                        break;
                    case 15:
                        //新乡镇样式//---a
                        fragmentList.add(newsService.getTown2ListMainFragment(secMenu.getUrl()));
                        break;
                    case 16:
                        //新活动
                        fragmentList.add(activitiesService.getActivityTempFragment("", false, 1));
                        break;
                    case 22:
                        fragmentList.add(liveService.getNewLiveListFragment());
                        break;
                    case 24:
                        fragmentList.add(newsService.getJLNewsListFragment(0));
                        break;
                    case 25:
                        fragmentList.add(newsService.getJLNewsListFragment(1));
                        break;
                    case 26:
                        fragmentList.add(newsService.getJLMultiNewsFragment());
                        break;
                    case 29:
                    case 37:
                        fragmentList.add(practiceService.getPracticeHomeFragment(secMenu.getUrl(), secMenu.getMenuName(), true, true));
                        break;
                    case 50:
                        fragmentList.add(newsService.getTitleNewsFragment("", secMenu.getUrl(), "", true));
                        break;
                    case 52:
                        fragmentList.add(newsService.getProgramFragment(secMenu.getSecondId() + "", "-1", false));
                        break;
                    case 55:
                        fragmentList.add(liveService.getNanBuLiveFragment());
                        break;
                    default:
                        fragmentList.add(new TextFragment());
                        break;
                }
            }
        } else {
            fragmentList.add(new HomeListFragment());
            names = new String[]{"推荐"};
        }
        homeView.setNavigation(fragmentList, names);
    }
}
